package com.cehome.cloudbox.config;
import com.cehome.cloudbox.listener.*;
import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType;
import org.flowable.common.engine.api.delegate.event.FlowableEventDispatcher;
import org.flowable.spring.SpringProcessEngineConfiguration;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ContextRefreshedEvent;

import javax.annotation.Resource;

/**
 * 全局监听配置 ContextRefreshedEvent在类被初始化之后触发
 *
 * @author NCIT
 * @date 2021/8/24
 */
@Configuration
public class FlowableGlobListenerConfig implements ApplicationListener<ContextRefreshedEvent> {
    @Resource
    private SpringProcessEngineConfiguration configuration;
    @Resource
    private GlobalMultiInsActStartedListener globalMultiInsActStartedListener;
    @Resource
    private GlobalTaskCreateListener globalTaskCreateListener;
    @Resource
    private GlobalTaskCompletedListener globalTaskCompletedListener;
    @Resource
    private GlobalProcessCompletedListener globalProcessCompletedListener;
    @Resource
    private GlobalProcessCancelledListener globalProcessCancelledListener;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
//        //暂时移除-----监听配置
//        FlowableEventDispatcher dispatcher = configuration.getEventDispatcher();
//        // 全局的多实例任务启动监听
//        dispatcher.addEventListener(globalMultiInsActStartedListener, FlowableEngineEventType.MULTI_INSTANCE_ACTIVITY_STARTED);
//        // 任务创建全局监听
//        dispatcher.addEventListener(globalTaskCreateListener, FlowableEngineEventType.TASK_CREATED);
//        // 任务完成全局监听
//        dispatcher.addEventListener(globalTaskCompletedListener, FlowableEngineEventType.TASK_COMPLETED);
//        // 流程完成全局监听
//        dispatcher.addEventListener(globalProcessCompletedListener, FlowableEngineEventType.PROCESS_COMPLETED);
//        // 流程取消全局监听
//        dispatcher.addEventListener(globalProcessCancelledListener, FlowableEngineEventType.PROCESS_CANCELLED);
    }
}
